package com.sx.jys.app.net

import com.sx.jys.app.net.bean.AccountBean
import com.sx.jys.app.net.bean.ApiPageResponse
import com.sx.jys.app.net.bean.ApiResponse
import com.sx.jys.app.net.bean.CkNumBean
import com.sx.jys.app.net.bean.CoinBean
import com.sx.jys.app.net.bean.EmptyDataApiResponse
import com.sx.jys.app.net.bean.FxBeanList
import com.sx.jys.app.net.bean.HomeListBean
import com.sx.jys.app.net.bean.LoginBean
import com.sx.jys.app.net.bean.OrderBean
import com.sx.jys.app.net.bean.RespConfig
import com.sx.jys.app.net.bean.SwithcBean
import retrofit2.http.Query


//双重校验锁式-单例 封装NetApiService 方便直接快速调用简单的接口
val apiService: ApiService by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
    NetworkApi.INSTANCE.getApi(ApiService::class.java, ApiService.SERVER_URL)
}

val HttpRequestCoroutine: HttpRequestManger by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
    HttpRequestManger()
}

class HttpRequestManger {

    suspend fun login(
        phone: String, passWord: String
    ): ApiResponse<LoginBean> {
        return apiService.login(phone, passWord)
    }

    suspend fun homeList(type: Int): ApiResponse<HomeListBean> {
        return apiService.homeList(type)
    }

    suspend fun ckList(current: Int, status: String?): ApiResponse<ApiPageResponse<OrderBean>> {
        return apiService.ckList(current, status)
    }

    suspend fun ckSecondList(
        code: String, openTime: String, current: Int, status: String?
    ): ApiResponse<ApiPageResponse<OrderBean>> {
        return apiService.ckSecondList(code, current, openTime, status)
    }


    //1开启 2关闭
    suspend fun orderSwitch(type: String): EmptyDataApiResponse {
        return apiService.orderSwitch(type)
    }

    suspend fun switchSelect(enu: String): ApiResponse<SwithcBean> {
        return apiService.switchSelect(enu)
    }

    suspend fun logOut(): EmptyDataApiResponse {
        return apiService.logOut()
    }

    suspend fun ckNum(): ApiResponse<CkNumBean> {
        return apiService.ckNum()
    }

    suspend fun accountList(): ApiResponse<MutableList<AccountBean>> {
        return apiService.accountList()
    }

    suspend fun currList(): ApiResponse<MutableList<FxBeanList>> {
        return apiService.currList()
    }

    suspend fun currSet(bean: FxBeanList): EmptyDataApiResponse {
        return apiService.currSet(bean)
    }

    suspend fun coinList(): ApiResponse<MutableList<CoinBean>> {
        return apiService.coinList()
    }

    suspend fun recordingOrder(
        code: String,
        id: String,
        orderType: Boolean,
        multiple: String,
        stopPrice: String,
        losePrice: String,
        entrustedPrice: String
    ): EmptyDataApiResponse {
        return apiService.recordingOrder(
            code,
            id,
            if (orderType) "1" else "2",
            multiple,
            stopPrice,
            losePrice,
            entrustedPrice
        )
    }

    suspend fun closeAll(
        code: String? = null, openTime: String? = null, isOneOrder: String? = null
    ): EmptyDataApiResponse {
        return apiService.closeAll(code, openTime, isOneOrder)
    }

    suspend fun configSetting(
        keyval: String,
        vals: String
    ): EmptyDataApiResponse {
        return apiService.configSetting(RespConfig(keyval, vals))
    }

    suspend fun marginLimit(id: String, limit: String): EmptyDataApiResponse {
        return apiService.marginLimit(id, limit)
    }

    suspend fun leverageAllLimit(leverage: String): EmptyDataApiResponse {
        return apiService.leverageAllLimit(leverage)
    }

    suspend fun setProfitloss(
        code: String, openTime: String, stopPrice: String?="", losePrice: String?=""
    ): EmptyDataApiResponse {
        return apiService.setProfitloss(code, openTime, stopPrice, losePrice)
    }

    suspend fun orderBack(code: String,openTime: String):EmptyDataApiResponse{
        return apiService.orderBack(code, openTime)
    }
}